# -*- coding: utf-8 -*-
"""
@Time : 2024/3/6 12:36 AM
@Author: imamhusan
@Des: 描述
"""
# import win32api
# import win32print
#
# def print_text_document(file_path, printer_name):
#     try:
#         win32api.ShellExecute(0, "printto", file_path, f'"{printer_name}"', ".", 0)
#         print(f"Printing {file_path} to {printer_name}")
#     except Exception as e:
#         print(f"Failed to print: {e}")
#
# def print_image(image_path, printer_name):
#     try:
#         win32api.ShellExecute(0, "print", image_path, f'"{printer_name}"', ".", 0)
#         print(f"Printing {image_path} to {printer_name}")
#     except Exception as e:
#         print(f"Failed to print: {e}")
#
# # 使用示例
# document_path = "path_to_document.docx"
# image_path = "path_to_image.jpg"
# printer_name = "Your_Printer_Name"
#
# print_text_document(document_path, printer_name)
# print_image(image_path, printer_name)

#
# import fitz
# import win32api
# import win32print
#
# def print_pdf(pdf_path, printer_name):
#     try:
#         pdf_document = fitz.open(pdf_path)
#         for page_num in range(pdf_document.page_count):
#             page = pdf_document.load_page(page_num)
#             pix = page.get_pixmap(matrix=fitz.Matrix(300/72, 300/72))  # 300 dpi
#             image_path = f"temp_page_{page_num}.png"
#             pix.writePNG(image_path)
#             print_image(image_path, printer_name)
#     except Exception as e:
#         print(f"Failed to print PDF: {e}")
#
# def print_image(image_path, printer_name):
#     try:
#         win32api.ShellExecute(0, "print", image_path, f'"{printer_name}"', ".", 0)
#         print(f"Printing {image_path} to {printer_name}")
#     except Exception as e:
#         print(f"Failed to print image: {e}")
#
# # 使用示例
# pdf_path = "path_to_pdf.pdf"
# printer_name = "Your_Printer_Name"
#
# print_pdf(pdf_path, printer_name)


